package com.ddstation.onsitelaw.service;

import com.ddstation.onsitelaw.entity.DtInvsManageInstitutionEntity;
import com.ddstation.onsitelaw.entity.DtInvsManageInstitutionSupervisorEntity;
import com.ddstation.onsitelaw.mapper.DtInvsManageInstitutionMapper;
import com.ddstation.onsitelaw.mapper.DtInvsManageInstitutionSupervisorMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;

import javax.inject.Inject;
import java.util.List;

/**
 * @author 忆秋枫
 */
@Service
public class DtInvsManageInstitutionServiceImpl implements DtInvsManageInstitutionService {

    @Inject
    private DtInvsManageInstitutionMapper dtInvsManageInstitutionMapper;
    @Inject
    private DtInvsManageInstitutionSupervisorMapper dtInvsManageInstitutionSupervisorMapper;

    @Override
    @Transactional(readOnly = true)
    public DtInvsManageInstitutionEntity selectById(String id) {
        return dtInvsManageInstitutionMapper.selectById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<DtInvsManageInstitutionEntity> selectByAddress(String province, String city, String county) {
        return dtInvsManageInstitutionMapper.selectByAddress(province, city, county);
    }


    @Override
    @Transactional(readOnly = true)
    public DtInvsManageInstitutionSupervisorEntity selectByWxUserId(int wxUserId) {

        Example example = new Example(DtInvsManageInstitutionSupervisorEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("wxUserId", wxUserId);
        List<DtInvsManageInstitutionSupervisorEntity> userEntityList = dtInvsManageInstitutionSupervisorMapper.selectByExample(example);
        if (ObjectUtils.isEmpty(userEntityList)) {
            return null;
        }
        return userEntityList.get(0);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateWxUserId(int supervisorId, int wxUserId) {
        dtInvsManageInstitutionSupervisorMapper.updateWxUserId(supervisorId, wxUserId);
    }

}